package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25397
 * Date: 2022-03-24
 * Time: 21:42
 */
public class Demo10 {
    private static boolean isQuit=false;
    public static void main(String[] args) {
        Thread t=new Thread(()->{
           while(!isQuit){
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        t.start();

        //只要把isQuit设置成true，这个while循环就结束
        //进一步的run就执行完了，再进一步就是线程执行结束
        try {
            Thread.sleep(5000);//我们要休眠5s，然后设置isQuit=true
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        isQuit=true;
        System.out.println("t线程终止" );
    }
}
